<template lang="">
    <div>
        <h1>展示详情信息</h1>
        <table border=1 cellspacing=0>
            <tr>
                <td>标题</td>
                <td>内容</td>
            </tr>
            <tr v-for='i in article'>
                    <td>{{i.title}}</td>
                    <td>{{i.content}}</td>
                </tr>
        </table>
        <br/><br/><br/>
        <van-field type='textarea' v-model='form.content'/>
        <van-button @click='add'>评论</van-button>

        <br/><br/><br/>

        <table border=1 cellspacing=0>
            <tr>
                <td>用户名</td>
                <td>内容</td>
            </tr>
            <tr v-for='i in clist'>
                    <td>{{i.name}}</td>
                    <td>{{i.content}}</td>
                </tr>
        </table>
    </div>
</template>

<script>
export default {
    data(){
        return{
            id:this.$route.query.id,
            article:{},
            form:{'userid':localStorage.getItem('userid'),'aid':this.id},
            clist:[]
        }
    },
    methods:{
        getArticle(){
            this.axios.get('articleM?id='+this.id).then(res=>{
                this.article = res.data.article
            })
        },
        //添加评论
        add(){
            if(this.form.userid){
                //调用评价接口添加
                this.axios.post('commentM',this.form).then(res=>{
                    this.getComment()
                })
            }else{
                //跳转到登录页
            }
        },
        getComment(){
            this.axios.get('commentM?aid='+this.id).then(res=>{
                this.clist = res.data.list
            })
        }
    },
    mounted(){
        this.getArticle()
        this.getComment()
    }
}
</script>

<style lang="">

</style>